package com.kelvin.paopao.module.peisong.mypeisong.myorder;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.kelvin.paopao.R;
import com.kelvin.paopao.adapter.MyDateAdapter;
import com.kelvin.paopao.adapter.MyOrderAdapter;
import com.kelvin.paopao.api.responseBean.DateListModel;
import com.kelvin.paopao.api.responseBean.OrderModel;
import com.kelvin.paopao.injector.components.DaggerMyDateComponent;
import com.kelvin.paopao.injector.components.DaggerMyOrderComponent;
import com.kelvin.paopao.injector.modules.MyDateModule;
import com.kelvin.paopao.injector.modules.MyOrderModule;
import com.kelvin.paopao.module.base.BaseFragment;
import com.kelvin.paopao.module.main.date.dateperson.DatePersonActivity;
import com.kelvin.paopao.module.main.date.mydate.mypublish.IMyPublishDatePresenter;
import com.kelvin.paopao.module.main.date.mydate.mypublish.IMyPublishDateView;
import com.kelvin.paopao.module.peisong.mypeisong.peisongperson.PeisongPersonActivity;
import com.kelvin.paopao.module.person.photoset.PhotoSetActivity;
import com.kelvin.paopao.widgets.EmptyLayout;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;

/**
 * Created by MCK on 2017/5/17.
 */

public class MyOrderFragment extends BaseFragment<MyOrderPresenter>
        implements IMyOrderView {
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.empty_layout)
    EmptyLayout emptyLayout;

    @Inject
    MyOrderAdapter adapter;


    private LinearLayoutManager manager;

    @Override
    protected int attachLayoutRes() {
        return R.layout.fragment_my_publish_date;
    }

    @Override
    protected void initInjector() {
        DaggerMyOrderComponent.builder().myOrderModule(new MyOrderModule(this)).build().inject(this);
    }

    @Override
    protected void initViews() {
        manager = new LinearLayoutManager(getContext());
        recyclerView.setLayoutManager(manager);

        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                PeisongPersonActivity.launch(getContext(),
                        ((OrderModel) adapter.getData().get(position)).getOId());
            }
        });
        recyclerView.setAdapter(adapter);
    }

    @Override
    protected void updateViews(boolean isRefresh) {
        mPresenter.getData(isRefresh);
    }

    @Override
    public void loadData(List<OrderModel> orderModels) {
        adapter.setNewData(orderModels);
    }

    @Override
    public void showNodata() {
        View nodataView = LayoutInflater.from(getContext()).inflate(R.layout.view_no_data,
                (ViewGroup) recyclerView.getParent(), false);
        adapter.setEmptyView(nodataView);
    }

    public static MyOrderFragment newInstance() {
        Bundle args = new Bundle();
        MyOrderFragment fragment = new MyOrderFragment();
        fragment.setArguments(args);
        return fragment;
    }
}
